package cc.sbootd2.sbootd2web.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import cc.sbootd2.sbootd2web.pojo.User;
import cc.sbootd2.sbootd2web.service.UserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("/dologin")
    public String dologin(Model model, User user, HttpSession session){
        User user1= userService.getUserByUserCode(user.getUserCode());

        if(user1!=null){

            if(user.getUserPassword().equals(user1.getUserPassword())){
                session.setAttribute("loginUser",user1);
                return "redirect:/admin/index.jsp";

            }else{
                model.addAttribute("error","密码错误!");
            }

        }else{
            model.addAttribute("error","用户不存在!");
        }


        return "forward:/admin/login.jsp";






    }


}
